package com.smart.wap.app;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.manager.member.entities.models.MemberPigSale;
import com.smart.manager.member.entities.models.MemberPigSaleBill;
import com.smart.utils.MemberStp;
import com.smart.wap.bodys.SaleBody;
import com.smart.wap.service.SaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author Administrator
 */

@Api(tags = "移动端-猪仔拍卖场")
@RestController
@RequestMapping(SmartConstant.WAP_API_PREFIX + "sale")
@RequiredArgsConstructor
public class SaleController {
    private final SaleService saleService;

    @ApiOperation(value = "获取拍卖列表")
    @GetMapping(value = "getPageList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<Page<MemberPigSale>> getPageList(@Validated SaleBody.SearchBody search) {
        Page<MemberPigSale> result = saleService.getPageList(search);
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "获取我购买的")
    @GetMapping(value = "getPurchase")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<Page<MemberPigSaleBill>> getPurchase(@Validated SaleBody.SearchBody search) {
        search.setIs(true);
        Page<MemberPigSaleBill> result = saleService.getBillList(search);
        return AjaxResult.data(result);
    }

    @ApiOperation(value = "获取我售卖的")
    @GetMapping(value = "getSale")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<Page<MemberPigSaleBill>> getSale(@Validated SaleBody.SearchBody search) {
        search.setIs(false);
        Page<MemberPigSaleBill> result = saleService.getBillList(search);
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "添加拍卖物品")
    @PostMapping(value = "addSale")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<String> addSale(SaleBody.EditBody body) {
        saleService.addSale(body);
        return AjaxResult.success();
    }


    @ApiOperation(value = "购买拍卖物品")
    @PostMapping(value = "buy")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<String> addSale(SaleBody.PurchaseBody body) {
        saleService.purchaseSale(body);
        return AjaxResult.success();
    }

}
